﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace Kamikaze
{
    class Objeto2D
    {
        public Texture2D texture;
        public Vector2 posicao;
        public Vector2 posicaoChao; 
        public Color cor;
        public Vector2 vetorEscala;
        public Vector2 vetorOrigem;
        public Rectangle collisionBounds;
        public Rectangle retanguloDeCorte;
        public float rotacao;
        public float alpha;
        public SpriteEffects efeito;
        public bool visible;
        //public Texture2D teste;
        //public SoundEffect effect;
        

         
        public Objeto2D(Texture2D texture)   
        {
            this.texture = texture;
            //this.teste= texture;
            posicao = new Vector2(300, 300);
            posicaoChao = new Vector2(300, 300);
            cor = Color.White;
            rotacao = 0;
            vetorOrigem = new Vector2(texture.Width / 2, texture.Height / 2);
            vetorEscala = new Vector2(1, 1);
            alpha = 1;
            calcularRetangulo();

            retanguloDeCorte = new Rectangle(0, 0, texture.Width, texture.Height);

            efeito = SpriteEffects.None;
            //effect = (Game1.Self.Content.Load<SoundEffect>(@"Sounds/button-30"));

            visible = true;

            

            
        }

        public virtual void calcularRetangulo()
        {
            collisionBounds = new Rectangle(
                (int)(posicao.X - (vetorOrigem.X * vetorEscala.X)),
                (int)(posicao.Y - (vetorOrigem.Y * vetorEscala.Y)),
                (int)(texture.Width * vetorEscala.X), 
                (int)(texture.Height * vetorEscala.Y));
        }

         public bool hitTestObject(Objeto2D objeto)
        {
            this.calcularRetangulo();
            objeto.calcularRetangulo();

            if (this.collisionBounds.Intersects(objeto.collisionBounds))
            {
                return true;
            }
            else
            {
                return false;
            }
        }



        public void Draw(SpriteBatch spriteBatch)
        {
            if (visible == true)
            {
                spriteBatch.Draw(texture, posicao, retanguloDeCorte, cor, rotacao, vetorOrigem, vetorEscala, SpriteEffects.None, 0.5f);

            }
            
             
        }

                      

    }
}
